    subroutine fai_resort(icore, isympopa, isympopb, & 
                              isymvrta, isymvrtb, nvmax, nomax)
      use mod_symm
      use mod_iop
      use mod_orbit
      use mod_size
      use mod_ioff
      implicit none
      integer, intent(in) :: nvmax, nomax
      integer*8, intent(in) :: isymvrta(nvmax,8), isymvrtb(nvmax,8)
      integer*8, intent(in) :: isympopa(nomax,8), isympopb(nomax,8)
      real*8, intent(in) :: icore(*)

      if(prec==4) then 
         call fai_resort_s(icore, isympopa, isympopb, &
                                    isymvrta, isymvrtb, nvmax, nomax)
!     elseif(prec==8) then 
!        call fai_resort_d(icore, isympopa, isympopb, &
!                                   isymvrta, isymvrtb)
      endif
      return
      end

    subroutine fai_resort_s(icore, isympopa, isympopb, &
                              isymvrta, isymvrtb, nvmax, nomax)
      use mod_symm
      use mod_iop
      use mod_orbit
      use mod_size
      use mod_ioff
      implicit none
      integer, intent(in) :: nvmax, nomax
      integer*8, intent(in) :: isymvrta(nvmax,8), isymvrtb(nvmax,8)
      integer*8, intent(in) :: isympopa(nomax,8), isympopb(nomax,8)
      real*4, intent(in) :: icore(*)

     integer idx, nsize
     integer irrepa, numa, a, ain
     integer irrepi, numi, i, iin
     real*8, allocatable :: faiaa(:), faibb(:)
     logical yesno
     integer, external :: idsymsoc
     real*8, external :: nrm2so


     inquire(file='FAIAAR.dat', exist=yesno)
     if(yesno) then
        allocate(faiaa(nva*noa))
        call clmoioso0_s(1, icore, vrt(1,1), pop(1,1), 1, &
                              zorb, zorb, 1, 'FAIAAS__')
        open(unit=66, file='FAIAAR.dat', form='unformatted')
        rewind(66)
        read(66)(faiaa(i),i=1, nva*noa)
!       do i = 1, nva 
!          write(6,*)'faiaa',i,faiaa(i)
!       enddo
        close(66)
        call dtos(faiaa, icore, nva*noa)
        if(ldebug) then 
           write(6,*)'norm of faiaa',  nrm2so(nva*noa, icore, 1)
        endif
        idx = 0
        do irrepi = 1, nirrep
           irrepa = dirprd(irrepi, 1)
           numa = vrta(irrepa)
           numi = popa(irrepi)
           do i = 1, numi
           do a = 1, numa
              ain = isymvrta(a,irrepa)-noa
              iin = isympopa(i,irrepi)
              idx = idx+1
              icore(idx) = faiaa((iin-1)*nva+ain)
           enddo
           enddo
        enddo
        nsize = idsymsoc(1, vrta, popa, 1, zorb, zorb, 1)
        if(ldebug) then 
          write(6,*)'norm of faiaa',  nrm2so(nsize, icore, 1)
        endif
        call putallso_s(icore, 1, 'FAIAAS__')
     endif
     inquire(file='FAIBBR.dat', exist=yesno)
     if(yesno) then
        allocate(faibb(nvb*nob))
        call clmoioso0_s(1, icore, vrt(1,2), pop(1,2), 1, &
                              zorb, zorb, 1, 'FAIBBS__')
        open(unit=66, file='FAIBBR.dat', form='unformatted')
        rewind(66)
        read(66)(faibb(i),i=1, nvb*nob)
        close(66)
        call dtos(faibb, icore, nvb*nob)
        if(ldebug) then 
           write(6,*)'norm of faibb',  nrm2so(nvb*nob, icore, 1)
        endif
        idx = 0
        do irrepi = 1, nirrep
           irrepa = dirprd(irrepi, 1)
           numa = vrtb(irrepa)
           numi = popb(irrepi)
           do i = 1, numi
           do a = 1, numa
              ain = isymvrtb(a,irrepa)-nob
              iin = isympopb(i,irrepi)
              idx = idx+1
              icore(idx) = faibb((iin-1)*nvb+ain)
           enddo
           enddo
        enddo
        nsize = idsymsoc(1, vrtb, popb, 1, zorb, zorb, 1)
        if(ldebug) then 
           write(6,*)'norm of faibb',  nrm2so(nsize, icore, 1)
        endif
        call putallso_s(icore, 1, 'FAIBBS__')
     endif

      return
      end


